home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / xlib / sphere.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.7 KB  |  116 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <GL/glx.h>
  18. #include <GL/gl.h>
  19. #include <GL/glu.h>
  20. #include <stdio.h>
  21.  
  22. static long W = 300, H = 300;
  23. static int attributeList[] = {GLX_RGBA, None}; 
  24. static Bool WaitForNotify (Display *d, XEvent *e, char *arg)
  25. {
  26.     return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
  27. }
  28. static GLUquadricObj *qobj;
  29.  
  30. void gldrawing(void)
  31. {
  32.     glLoadIdentity();
  33.     glOrtho(-500.0, 500.0, -500.0, 500.0, -500.0, 500.0);
  34.     glClearColor(0.0, 0.0, 0.0, 0.0);
  35.  
  36.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  37.  
  38.     glColor3f(0.8, 0.4, 0.8);
  39.     glLineWidth(2.0);
  40.  
  41.     glPushMatrix();
  42.     glRotatef(20.0, 1,1,0);
  43.     gluQuadricDrawStyle(qobj, GLU_LINE);
  44.     gluSphere(qobj, 250.0, 25, 20);
  45.     glPopMatrix();
  46.  
  47.     glFlush();
  48. }
  49.  
  50. main(int argc, char **argv)
  51. {
  52.     Display *dpy;                 /* X Display */
  53.     XColor acolor;              /* Color definitions */
  54.     XVisualInfo *vi;              /* X Visual  */
  55.     Colormap cmap;                /* X Colormap */
  56.     XSetWindowAttributes swa;     /* X Window Attributes */
  57.     Window win;                   /* X Window Id */
  58.     GLXContext cx;                /* Extesion to X server; GLX context
  59.                      Data structure for X to hold GL global
  60.                      data, so that we don't have to send them
  61.                      to X through protocal everytime to
  62.                      eliminate X traffic */
  63.     XEvent event, report;         /* X event             */
  64.     int value;
  65.  
  66.                                   /* Standard code to open a X window */
  67.     dpy = XOpenDisplay (0);
  68.     XSynchronize(dpy, True);
  69.                                   /* get a appropriate visual */
  70.     vi = glXChooseVisual (dpy, DefaultScreen(dpy), attributeList);
  71.  
  72.                                       /* create a GLX context */
  73.     cx = glXCreateContext (dpy, vi, None, GL_FALSE);
  74.     
  75.                                   /* create a colormap using this visual */
  76.     cmap = XCreateColormap (dpy, RootWindow(dpy, vi->screen), vi->visual,
  77.                 AllocNone);
  78.  
  79.                                   /* create a X Window */
  80.     swa.colormap = cmap;
  81.     swa.border_pixel = 0;
  82.     swa.event_mask = StructureNotifyMask | KeyPressMask;
  83.     win = XCreateWindow (dpy, RootWindow(dpy,vi->screen), 0, 0, 500, 500,
  84.              0, vi->depth, InputOutput, vi->visual,
  85.              CWBorderPixel|CWColormap|CWEventMask, &swa);
  86.  
  87.     XSelectInput(dpy, win, ExposureMask | KeyPressMask |
  88.                                ButtonPressMask | StructureNotifyMask);
  89.     XMapWindow (dpy,win);
  90.                                   /* wait for window to map */
  91.     XIfEvent (dpy, &event,WaitForNotify, (char *)win);
  92.  
  93.                                   /* connect the context to the window */
  94.     if (!glXMakeCurrent(dpy,win,cx) == GL_TRUE) {
  95.     return 0;
  96.     }
  97.  
  98.     qobj = gluNewQuadric();
  99.     while (1) {
  100.     XNextEvent(dpy, &report);
  101.     switch (report.type) {
  102.         case KeyPress:
  103.         gluDeleteQuadric(qobj);
  104.                 XCloseDisplay(dpy);
  105.                 exit(1);
  106.         break;
  107.             case Expose:
  108.                 gldrawing();
  109.                 break;
  110.             default:
  111.                 break;
  112.     } /*end switch*/
  113.     } /*end while*/
  114. }
  115.  
  116.